<%-- 
    Document   : editProduct
    Created on : Mar 15, 2012, 9:26:56 PM
    Author     : rj
--%>


<%@page import="Model.ProductManager"%>
<%@page import="Model.DBConnection"%>
<%@page import="java.sql.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="../css/foo.css" type="text/css"></link>
        <link rel="stylesheet" type="text/css" href="../css/superfish.css" media="screen">	
        <title>Foobar</title>
        <script type="text/javascript" src="../js/jquery-1.7.1.min.js"></script>
        <script type="text/javascript" src="../js/hoverIntent.js"></script>
        <script type="text/javascript" src="../js/superfish.js"></script>
        <script type="text/javascript">

            // initialise plugins
            jQuery(function(){
                jQuery('ul.sf-menu').superfish();
            });
            
            function checkAuth(){
              if(<%=request.getParameter("loginAttempt")%> == false){
                 document.write('<span class="errLog">Authentication failed.</span>');
               }
         }

        </script>
    </head>
    
    <body class="bg">
        <% if(request.getSession(true).getAttribute("username") == null){ response.sendRedirect("../login.jsp"); } %>
          <script type="text/javascript">checkAuth();</script>
        <br/>
        <div class="hmenu">
            <% if (request.getSession(true).getAttribute("username") == null) {%>
           <p style="font-size: 12px; margin-top: -15px; float: right;">If you're not yet a member, sign up <a href="../signUp.jsp">here!</a> </p>   
           <% }%>
           <img src="../images/head.png" style="float: left; margin-left:20px;"></img>
            <div class="log">
                <% if (request.getSession(true).getAttribute("username") != null) {%>
                <h3>Welcome <%=session.getAttribute("username")%>!</h3>
                <br/>
<!--                insert stuff-->
                <a href="../LogoutServlet">Log out</a>
                <br>
                <br>
                <br>
                <p style="font-size: 10px; margin-top: -15px; float: right;">Click 
                    <a href="addProdType.jsp">here</a> to add a product type.</p><br/>
                <p style="font-size: 10px; margin-top: -15px; float: right;">Click 
                    <a href="../managerpages/changeMPassword.jsp">here</a> to change your password.</p>
                <% } else {%>
                <span style="font-weight: bold;">Log in</span>
                <form method="post" action="../LoginServlet">
                    <label>Username:</label><input type="text" name="username"/><br/>
                    <label>Password:</label><input type="password" name="password"/><br/>
                    <input type="submit" value="Log in" name="submit"/>
                </form>
                <% }%>
            </div>
                <% if (request.getSession(true).getAttribute("username") != null && Integer.parseInt(request.getSession(true).getAttribute("acctype").toString()) != 5 
                && Integer.parseInt(request.getSession(true).getAttribute("acctype").toString()) != 6 && Integer.parseInt(request.getSession(true).getAttribute("acctype").toString()) != 7){ %>
            <ul class="sf-menu">
                  <li class="current">
                    <a href="addProduct.jsp">Add a product</a>
                </li>
                <li>
                    <a href="editProduct.jsp">Edit a product</a>
                </li>
                <li>
                    <a href="cancelProduct.jsp">Cancel a product</a>
                    
                </li>
                <li>
                    <form action="../results.jsp">
                            <input type="text" name="search" placeholder="Enter your search"/>
                            <button>Go</button>
                    </form>
                </li>	
            </ul>
            <%  }else{ %>
             <ul class="sf-menu">
                <li class="current">
                    <a href="index.jsp">Home</a>
                </li>
                <li>
                    <a href="#">Products</a>
                    <ul>
                                        <%
                ResultSet rs = new ProductManager().getProductTypes();
                while(rs.next()){
                %>
                        <li>
                            <a href="products.jsp?prd=<%=rs.getInt("ProductTypeID")%>"><%=rs.getString("ProductType")%></a>
                        </li>
                <%}%>
                    </ul>
                </li>
                <li>
                    <a href="#">Stores</a>
                </li>
                <li>
                    <a href="#">Contact Us</a>
                </li>
                <li>
                    <a>SEARCH FUNCTION HERE</a>
                </li>
            </ul>
             <% } %>
        </div>
        <div class="content">
                <% if (request.getSession(true).getAttribute("username") != null && Integer.parseInt(request.getSession(true).getAttribute("acctype").toString()) != 5 
                && Integer.parseInt(request.getSession(true).getAttribute("acctype").toString()) != 6 && Integer.parseInt(request.getSession(true).getAttribute("acctype").toString()) != 7){ %>
  <b>Welcome to Foobar</b>
            <br/>
            Edit a Product<br/>
            <hr /> 

            
                 <%
                 
                 int prodHold = Integer.parseInt(request.getSession(true).getAttribute("acctype").toString());
                 if(prodHold > 4){
                     prodHold = prodHold - 3;
                 }
                 
                 String prodType = Integer.toString(prodHold);              
                              Model.DBConnection db = new DBConnection();
                              Connection con = db.getConnection();

                              Statement stmt = con.createStatement();   
                              ResultSet rs2 = stmt.executeQuery("Select * from product where ProductType = " + prodType + " AND ProductStatus = 1");
                              String ProductID = null;
                              String ProductTitle = null;
                              String ProductSynopsis = null;
                              String ProductPrice = null;
                              String ProductRating = null;
                              int ProductQuantity = 0;

                              //Integer Status = null;
                              %>
                
                              <% while(rs2.next()){
                                  ProductID = rs2.getString("ProductID");
                                  ProductTitle = rs2.getString("ProductTitle");
                                  ProductSynopsis = rs2.getString("ProductSynopsis");
                                  ProductRating = rs2.getString("ProductRating");
                                  ProductPrice = rs2.getString("ProductPrice");
                                  ProductQuantity = rs2.getInt("ProductQuantity");
                              %>

                                       <form method="post" action="../EditProductServlet">
                              <label><input type="hidden" value="<%=ProductID%>" name="ProductID"/></label>
                              Product Title: <%=ProductTitle%><br> <label><input type="text" name="ProductTitle"></label><br>
                              Product Synopsis: <%=ProductSynopsis%><br> <label><input type="text" name="ProductSynopsis"></label><br>
                              Product Rating[1-10]: <%=ProductRating%><br> <label><input type="text" name="ProductRating"></label><br>
                              Product Price: <%=ProductPrice%><br> <label><input type="text" name="ProductPrice"></label><br>
                              Product Quantity: <%=ProductQuantity%><br> <label><input type="text" name="ProductQuantity"></label><br>                              
                              <button type="submit" id="submitButton">Edit Product</button><br><br>
                              </form>
                              
                              <% } %>
                             
          
            <% } else { %>
            <h1>Oops! We don't think you're allowed to be here.</h1>
            <span>Please log in with the correct user credentials</span>
            <% } %>
        </div>
    </body>
</html>
